﻿using System;
using System.Windows.Forms;
using Google.GData.Spreadsheets;

namespace uk.org.aspellclark.todolistppc
{
    /// <summary>
    ///   <name>TodoListTreeNode</name>
    ///   <namespace>uk.org.aspellclark.todolistppc</namespace>
    ///   <version>1.0</version>
    ///   <author>Andy Aspell-Clark</author>
    ///   <description>
    ///   </description>
    ///   <history>
    ///     <historyitem> 1 Aug 2004  1.0 ARA  Initial Version.</historyitem>
    ///   </history>
    /// </summary>
    public class TodoListTreeNode : TreeNode
    {

        #region Constructors
        /// <summary>
        /// 
        /// </summary>
        /// <param name="psString"></param>
        public TodoListTreeNode(string psString)
            : base(psString)
        {
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="psString"></param>
        public TodoListTreeNode(ListEntry GoogleRow)
            : base(GoogleRow.Elements[1].Value)
        {
            Task = new SyncTask();
            Task.TaskId = Convert.ToInt32(GoogleRow.Elements[0].Value);
            Task.Title = GoogleRow.Elements[1].Value;
            if (GoogleRow.Elements[3].Value == "0")
            {
                Task.Complete = false;
            }
            else 
            {
                Task.Complete = true;
            }
            //Task.DoneDate = GoogleRow.Elements[4].Value;
            Task.CommentsStr = GoogleRow.Elements[5].Value;
            
            DateTime epoch = new DateTime(1970, 1, 1);
            Task.LastMod = epoch.AddSeconds(double.Parse(GoogleRow.Elements[12].Value.Substring(0,10)));


            //Task.DueDate = GoogleRow.Elements[7].Value;
            Task.ParentTaskId = Convert.ToInt32(GoogleRow.Elements[19].Value);
        }
        #endregion
        private int m_iTaskId = -1;
        private int m_iParentTaskId = -1;
        private SyncTask m_Task = null;

        /// <summary>
        /// 
        /// </summary>
        public SyncTask Task
        {
            get { return m_Task; }
            set { m_Task = value; }
        }
        /// <summary>
        /// 
        /// </summary>
        public int TaskId
        {
            get { return m_iTaskId; }
            set { m_iTaskId = value; }
        }
        /// <summary>
        /// 
        /// </summary>
        public int ParentTaskId
        {
            get { return m_iParentTaskId; }
            set { m_iParentTaskId = value; }
        }




        /// <summary>
        /// 
        /// </summary>
        public void Clicked(bool pbChecked)
        {
            Task.Complete = pbChecked;
            if (Task.Complete)
            {
                Task.PercentComplete = 100;
            }
            else
            {
                Task.PercentComplete = 0;
            }
        }
    }
}

